package cn.tedu.crm.business.controller;

import cn.tedu.crm.base.pojo.PageObject;
import cn.tedu.crm.base.response.JsonResult;
import cn.tedu.crm.business.pojo.dto.AssessLoadParam;
import cn.tedu.crm.business.pojo.dto.AssessSaveParam;
import cn.tedu.crm.business.pojo.vo.AssessVO;
import cn.tedu.crm.business.pojo.vo.DeptVO;
import cn.tedu.crm.business.pojo.vo.StaffVO;
import cn.tedu.crm.business.service.AssessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/crm/assess")
public class AssessController {

    @Autowired
    private AssessService assessService;

    @GetMapping("/load")
    public JsonResult<PageObject<AssessVO>> load(AssessLoadParam assessLoadParam) {
        log.debug("加载订单信息:{}",assessLoadParam);
        PageObject<AssessVO> pageObject = PageObject.page(assessLoadParam.getPageNum(), assessLoadParam.getPageSize(), () -> {
           return assessService.load(assessLoadParam);
        });
        return JsonResult.ok(pageObject);
    }
    @GetMapping("/loadDept")
    public JsonResult<List<DeptVO>> loadDept(){
        log.debug("加载部门信息");
        List<DeptVO> list =  assessService.loadDept();
        return JsonResult.ok(list);
    }
    @GetMapping("/loadStaff")
    public JsonResult<List<StaffVO>> loadStaff(Long deptId){
        log.debug("加载员工信息:{}",deptId);
        List<StaffVO> list =  assessService.loadStaff(deptId);
        return JsonResult.ok(list);
    }
    @PostMapping("/save")
    public JsonResult save(@RequestBody AssessSaveParam assessSaveParam){
        log.debug("保存业务指标信息:{}",assessSaveParam);
        assessService.save(assessSaveParam);
        return JsonResult.ok();
    }
    @GetMapping("/delete")
    public JsonResult delete(Long id){
        log.debug("删除业务指标信息:{}",id);
        assessService.delete(id);
        return JsonResult.ok();
    }
    @PostMapping("/select")
    public JsonResult<PageObject<AssessVO>> select(@RequestBody AssessLoadParam assessLoadParam){
        log.debug("查询业务指标信息:{}",assessLoadParam);
        PageObject<AssessVO> pageObject = PageObject.page(assessLoadParam.getPageNum(), assessLoadParam.getPageSize(), () -> {
            return assessService.select(assessLoadParam);
        });
        log.debug("查询当前用户的业务指标列表:出参{}",pageObject);
        return JsonResult.ok(pageObject);
    }
}
